package com.wanjl.springMvc.config;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
import org.springframework.web.servlet.support.AbstractDispatcherServletInitializer;

/**
 * @author WanJl
 * @version 1.0
 * @title ServletContainerInitConfig
 * @description
 * @create 2024/11/9
 */
//servlet的初始化配置类
//springMVC提供的快速的初始化web3.0容器的出现类
/*
public class ServletContainerInitConfig extends AbstractDispatcherServletInitializer {

    //加载springmvc配置类的，生成一个SpringMVC的容器，本质上还是spring的IOC容器
    @Override
    protected WebApplicationContext createServletApplicationContext() {
        //初始化WebApplicationContext对象
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        //加载springmvc配置类
        context.register(SpringMvcConfig.class);
        return context;
    }
    //设置由springMVC的控制器处理所有的请求
    @Override
    protected String[] getServletMappings() {
        //创建数组的三种方式：
        //1、String[] strings=new String[10];
        //2、String[] strings=new String[]{"张三","李四"};
        //3、String[] strings={"张三","李四"};
        return new String[]{"/"};
    }
    //加载spring的配置类
    @Override
    protected WebApplicationContext createRootApplicationContext() {
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
        context.register(SpringConfig.class);
        return context;
    }
}
*/

public class ServletContainerInitConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    /**
     * 获取并加载spring核心配置类
     * @return
     */
    @Override
    protected Class<?>[] getRootConfigClasses() {   //getxxxClasses()   XX类.class。 xxx对象.getClass()
        return new Class[]{SpringConfig.class};
    }

    /**
     * 获取并加载springMVC配置类
     * @return
     */
    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{SpringMvcConfig.class};
    }

    /**
     * 把所有的映射路径都交给springMVC处理
     * @return
     */
    @Override
    protected String[] getServletMappings() {
        return new String[]{"/"};
    }
}